package com.example.crm.servlet;

import com.example.crm.service.IUserService;
import com.example.crm.service.impl.UserServicelmpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/loginchk")
public class UserLoginCheckServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doGet(req, resp);
        //获取请求
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        System.out.println(username+"  "+password);
        //调用service查询
        IUserService service=new UserServicelmpl();
        boolean result=service.login(username,password);
        //请求转发or跳转页面
        if(result){
            System.out.println("success");
            resp.sendRedirect("index.jsp");
        }else{
            System.out.println("fail");
            resp.sendRedirect("login.jsp");
        }
    }
}
